/*
* WuManber.h - This file is the part of the StringSearch.
* Copyright (C) 2010 Dean Lee <deanlee3@gmail.com> <http://www.deanlee.cn/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
* Acknowledgements:
*   <> Many thanks to all of you, who have encouraged me to update my articles
*     and code, and who sent in bug reports and fixes.
* 
*/

#pragma once
#include "resource.h"       // main symbols

#include "StringSearch_i.h"

extern "C"
{
#include "mwm.h"
}
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif



// CWuManber

class ATL_NO_VTABLE CWuManber :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CWuManber, &CLSID_WuManber>,
	public IDispatchImpl<IWuManber, &IID_IWuManber, &LIBID_StringSearchLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CWuManber()
	{
		m_index = -1;
		m_handle = mwmNew();
	}

	void setIndex(int index);
	DECLARE_REGISTRY_RESOURCEID(IDR_WUMANBER)


	BEGIN_COM_MAP(CWuManber)
		COM_INTERFACE_ENTRY(IWuManber)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
		if (m_handle)
			mwmFree(m_handle);
	}

public:

	STDMETHOD(AddPatterns)(BSTR patterns, BSTR separator, VARIANT_BOOL caseSensitive);
	STDMETHOD(Search)(BSTR string, LONG* pIndex);
protected:
	void * m_handle;
	int m_index;
};

OBJECT_ENTRY_AUTO(__uuidof(WuManber), CWuManber)
